﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Web.SessionState;
using LcAudit.BPM.Core;
using LcAudit.BPM.Core.Bll;
using LcAudit.BPM.Core.Dal;
using LcAudit.BPM.Core.Model;
using LcAudit.Common;
using LcAudit.Common.ValidateCode;

namespace LcAudit.BPM.Admin
{
    public partial class LoginService : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request["loginName"]) && !string.IsNullOrEmpty(Request["loginPass"]) && !string.IsNullOrEmpty(Request["validateCode"]))
                {
                    string userName = Request["loginName"];
                    string password = Request["loginPass"];
                    int saveCookieDays = int.Parse(Request["validateCode"]);
                    //ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript",
                    //    "<script>login('" + name + "','" + pass + "','" + validateCode + "')</script>");


                    User u = UserDal.Instance.GetUserBy(userName);
                    if (u != null)
                    {
                        if (!u.IsDisabled)
                        {
                            bool flag = UserBll.Instance.UserLogin(userName, password, saveCookieDays);
                            if (flag)
                            {
                                Response.Redirect("/default.aspx");
                            }
                            else
                            {
                                //msg = new { success = false, message = "亲，用户名或密码不正确哦。" };
                                ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript",
                                    "<script>alert('用户名或密码不正确');history.go(-1);</script>");
                            }
                        }
                        else
                        {
                            //msg = new { success = false, message = "亲，您的帐号已被禁用，请联系管理员吧。" };
                            ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript",
                                   "<script>alert('您的帐号已被禁用，请联系管理员');history.go(-1);</script>");
                        }
                    }
                }
            }
        }
    }
}